package com.cjy.controller;

import com.cjy.entity.UserInfo;
import com.cjy.service.UserInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Cheng JiYe
 * @description:
 * @date 2021/4/3 20:09
 */
@RestController
public class UserInfoController {
  @Resource UserInfoService userInfoService;

  /**
   * 按username账户从数据库中取出用户信息
   *
   * @param username 账户
   * @return
   */
  @GetMapping("/userList")
  @RequiresPermissions("userInfo:view") // 权限管理.
  public UserInfo findUserInfoByUsername(@RequestParam String username) {
    return userInfoService.findByUsername(username);
  }

  /**
   * 简单模拟从数据库添加用户信息成功
   *
   * @return
   */
  @GetMapping("/userAdd")
  @RequiresPermissions("userInfo:add")
  public String addUserInfo() {
    return "addUserInfo success!";
  }

  /**
   * 简单模拟从数据库删除用户成功
   *
   * @return
   */
  @GetMapping("/userDelete")
  @RequiresPermissions("userInfo:delete")
  public String deleteUserInfo() {
    return "deleteUserInfo success!";
  }
}
